package com.campus.mapper;

import com.campus.annotation.AutoFill;
import com.campus.enumeration.OperationType;
import com.campus.pojo.entity.Course;
import com.campus.pojo.vo.CourseVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CourseMapper {
    /**
     * 插入课程信息
     *
     * @param course 课程信息
     */
    @Insert("INSERT INTO course(course_name, course_code, teacher, weekday, start_time, end_time, classroom, weeks, create_time, update_time) " +
            "VALUES(#{courseName}, #{courseCode}, #{teacher}, #{weekday}, #{startTime}, #{endTime}, #{classroom}, #{weeks}, #{createTime}, #{updateTime})")
    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")// 返回主键id并插入到user_course表中
    void insertCourse(Course course);

    /**
     * 查询所有课程信息
     *
     * @return 课程信息列表
     */
    @Select("select * from course")
    List<CourseVO> getCourses();
}
